/*
ID: icerupt1
PROG: pprime
LANG: C++11
*/
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int a, b;

int get_len(int x)
{
	return int(log(x)/log(10)) + 1;
}

string num_to_string(int n, int len)
{
	int tlen = get_len(n);
	string s(len-tlen, '0');
	s += to_string(n);
	return s;
}

string string_reverse(string a)
{
	reverse(a.begin(), a.end());
	return a;
}

bool prime(int x)
{
	for (int i = 2; i*i <= x; i++)
		if (x % i == 0) return false;
	return true;
}

int main()
{
	ifstream fin {"pprime.in" };
	ofstream fout{"pprime.out"};

	fin >> a >> b;
	int lena = get_len(a);
	int lenb = get_len(b);

	vector<int> ans;
	for (int leni = lena; leni <= lenb; leni++) {
		int max_num = int(pow(10, leni>>1)) - 1;
		if (leni == 1) {
			for (int i = a; i <= 9; i++)
				if (prime(i)) ans.push_back(i);
		} else
		for (int i = 1; i <= max_num; i++) {
			string second_half = num_to_string(i, leni>>1);
			string first_half = string_reverse(second_half);
			if (leni & 1) {
				for (char i = '0'; i <= '9'; i++) {
					int num = stoi(first_half + i + second_half);
					if (num > b) break;
					if (num < a) continue;
					if (prime(num)) ans.push_back(num);
				}
			} else { // any even palindrome is divisible by 11
				int num = stoi(first_half + second_half);
				if (num > b) break;
				if (num < a) continue;
				if (prime(num)) ans.push_back(num);
			}
		}
	}
	sort(ans.begin(), ans.end());
	for (auto v:ans) fout << v << "\n";
}
